package com.yingside.gui;

import javax.swing.*;
import java.awt.*;

public class TestGridlayout extends JFrame {
    private JButton btn1,btn2,btn3,btn4,btn5,btn6;

    public TestGridlayout(){
        this.setTitle("表格布局窗口");

        //设置窗口的位置和大小可以合并为一句代码
        this.setBounds(300,300,400,400);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 表格布局
        // 以行和列的方式进行布局，默认有四个参数，几行，几列，水平间距，垂直间距
        this.setLayout(new GridLayout(2,2,5,5));
        btn1 = new JButton("1");
        btn2 = new JButton("2");
        btn3 = new JButton("3");
        btn4 = new JButton("4");
        btn5 = new JButton("5");
        btn6 = new JButton("6");

        this.add(btn1);
        this.add(btn2);
        this.add(btn3);
        this.add(btn4);
        this.add(btn5);
        this.add(btn6);



        //this.setVisible(true);
    }

    public static void main(String[] args) {
        TestGridlayout ff = new TestGridlayout();
        ff.setVisible(true);
    }
}
